<template>
  <section class="section-service">
    <div class="container">
      <div class="row row-cols-1 row-cols-md-4 g-4">
        <template v-for="(item, index) in result.list" :key="index">
          <div class="col">
            <div class="card h-100" style="">
              <img
                :src="
                  $getImgUrlFromMediaById(item.featured_media_src_url)
                    ? $getImgUrlFromMediaById(item.featured_media_src_url)
                    : require('@/assets/image/banner-default.png')
                "
                class="card-img-top"
                alt="..."
                style="height: 20vh"
              />
              <div class="card-body">
                <p
                  class="card-text text-center"
                  style="color: rgb(132, 141, 145)"
                >
                  {{ $wordpressDecodeHTML(item.title.rendered) }}
                </p>
              </div>
            </div>
          </div>
        </template>
      </div>
    </div>
  </section>
</template>

<script>
import { getArticleList } from "@/api/index";

import {
  reactive,
  toRefs,
  onBeforeMount,
  onMounted,
  getCurrentInstance,
  computed,
} from "vue";

export default {
  name: "ServiceIndex",
  components: {},
  props: {},
  setup() {
    const { proxy } = getCurrentInstance();
    const data = reactive({
      params: {
        page: 1,
        per_page: 99,
        categories: 3,
        // search: computed(() => (proxy.$route.query.keyword ? proxy.$route.query.keyword : "")),
      },
      result: {
        list: [],
        total: 0,
      },
    });
    const refData = toRefs(data);
    onBeforeMount(async () => {
      await methods.getList();
    });
    onMounted(() => {});
    //
    const methods = {
      jumpDetail(id) {
        proxy.$router.push(`/service/detail/${id}`);
      },
      async getList() {
        await getArticleList(data.params).then((res) => {
          // 获取总数
          let headers = res.headers;
          data.result.total = parseInt(headers["x-wp-total"]);
          //
          data.result.list = res.data;
        });
      },
    };
    //
    //
    return {
      ...refData,
      ...methods,
    };
  },
};
</script>
<style lang="scss" scoped>
.section-service {
  padding: 100px 0;
}
</style>
